<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\controllers\CommonController;
use app\models\Category;
use app\models\Product;
use yii\data\Pagination;

class ProductController extends CommonController
{
    public function actionIndex()
    {
        $this->layout="layout2.php";
        $tui= Product::find()->where('istui=:tui',[':tui'=>'1'])->all();//热卖
        $sale= Product::find()->where('issale=:sale',[':sale'=>'1'])->limit(5)->all();
        $hot= Product::find()->where('ishot=:hot',[':hot'=>'1'])->limit(5)->all();
        
        $productAll= Product::find();
        $count=$productAll->count();
        $pageSize=5;
        $pager=new Pagination(['totalCount'=>$count,'pageSize'=>$pageSize]);
        $totalList=$productAll->offset($pager->offset)->limit($pager->limit)->all();
        return $this->render('index',['tui'=>$tui,'sale'=>$sale,'hot'=>$hot,'totalList'=>$totalList,'pager'=>$pager]);
    }
    
    public function actionDetail()
    {
        $this->layout="layout2.php";
        if(\Yii::$app->request->isGet){
            $productid= Yii::$app->request->get('productid');
            $model= Product::find()->where('productid=:pid',[':pid'=>$productid])->one();
        }
        return $this->render('detail',['model'=>$model]);
    }
    
    
}
